package com.glacier.yuyuan.modules.admin.sys.service.impl;

import com.glacier.common.support.service.impl.TreeServiceImpl;
import com.glacier.yuyuan.modules.admin.sys.domain.Menu;
import com.glacier.yuyuan.modules.admin.sys.mapper.MenuMapper;
import com.glacier.yuyuan.modules.admin.sys.mapper.RoleMenuMapper;
import com.glacier.yuyuan.modules.admin.sys.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * date 2022-11-10 12:11
 * 菜单业务层
 *
 * @author glacier
 * @version 1.0
 */
@Transactional(readOnly = true)
@Service
public class MenuServiceImpl extends TreeServiceImpl<MenuMapper, Menu> implements MenuService {

    private RoleMenuMapper roleMenuMapper;

    protected MenuServiceImpl() {
        super(MenuMapper.class);
    }

    @Autowired
    public void setRoleMenuMapper(RoleMenuMapper roleMenuMapper) {
        this.roleMenuMapper = roleMenuMapper;
    }

    /**
     * 根据用户id 查询菜单
     *
     * @param userId
     * @return
     */
    @Override
    public List<Menu> findListByUserId(String userId) {
        return mapper.findListByUserId(userId);
    }

    /**
     * 删除回调
     *
     * @param idList
     */
    @Override
    protected <ID extends Serializable> void afterBatchDelete(final List<ID> idList) {
        if (!idList.isEmpty()) {
            // 删除菜单和角色关系
            roleMenuMapper.deleteByMenuIds(idList);
        }
    }
}
